*    ****************************************************************************  	*
*    File-Name: Guerineau_Leon_JFS2019                                 			 	*
*    Replication codes for:                                          			  	*
*    Guérineau, S. and Léon, F. (2019) "Information sharing, credit booms and  		*
*    financial stability: Dodeveloping economies differ from advanced countries?"  	*
*	 Journal of Financial Stability, 40, 64-76										*
*    ****************************************************************************  	*


clear all 
cd "C:\Users\florian.leon\Desktop\Recherche\Projets achevés\Outputs\Replication\JFS 2019"
use base_JFS2019.dta
set more off
set matsize 450


	**************************
	*   DATA AND VARIABLES   *
	**************************
	
xtset id year

***Dependent variable 
gen DNPL_IMF=(NPL_IMF-L.NPL_IMF)
gen D_NPL=NPL_LOAN-L.NPL_LOAN

***Interest variables

gen credit_boom=1 if pcgdp_gr>0 &  L1.pcgdp_gr>0 &  L2.pcgdp_gr>0 
replace credit_boom=0 if pcgdp_gr<=0 |  L.pcgdp_gr<=0 |  L2.pcgdp_gr<=0
replace credit_boom=. if pcgdp_gr==. |  L.pcgdp_gr==. |  L2.pcgdp_gr==.

gen credit_boom_1=credit_boom
replace credit_boom_1=0 if pcgdp_gr+L.pcgdp_gr+L2.pcgdp_gr<3
gen credit_boom_2=credit_boom
replace credit_boom_2=0 if pcgdp_gr+L.pcgdp_gr+L2.pcgdp_gr<6
gen credit_boom_3=credit_boom
replace credit_boom_3=0 if pcgdp_gr+L.pcgdp_gr+L2.pcgdp_gr<9
gen credit_boom_4=credit_boom
replace credit_boom_4=0 if pcgdp_gr+L.pcgdp_gr+L2.pcgdp_gr<12
gen credit_boom_5=credit_boom
replace credit_boom_5=0 if pcgdp_gr+L.pcgdp_gr+L2.pcgdp_gr<15 

replace gdppc=log(gdppc)


	**************************
	*          SAMPLE        *
	**************************

xtset id year
global X L.gdppc L.pcgdp L.inflation L.growth L.capital L.Der L.HHI
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
gen sample=e(sample)

	**************************
	* DESCRIPTIVE STATISTICS *
	**************************
	
	***Table 1
sum D_NPL if sample==1, detail
sum D_NPL if sample==1 & INCOME>2, d
sum D_NPL if sample==1 & INCOME<=2, d

sum pcgdp_gr if sample==1, detail
sum pcgdp_gr if sample==1 & INCOME>2, d
sum pcgdp_gr if sample==1 & INCOME<=2, d

	***Table 2
sum SHOCK_3 L.credit_boom_3 L.info_depth L.info_cov $X if e(sample)==1
corr SHOCK_3 L.credit_boom_3 L.info_depth L.info_cov $X if e(sample)==1


	**************************
	*  BASELINE REGRESSIONS  *
	**************************

	***Table 3
*Marginale effects are computed at the end of each code (scalar list) 
*and std. errors are extracted from regression
xtset id year
global X L.gdppc L.pcgdp L.inflation L.growth L.capital L.Der L.HHI

*Column (1) 
xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/977))
scalar list 
scalar drop _all
drop hatx


*Column (2)
xtprobit SHOCK_3 L.info_cov $X i.year if L.credit_boom_3!=., re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_cov $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/977))
scalar list 
scalar drop _all
drop hatx

*Column (3)
xtprobit SHOCK_3 L.info_depth $X i.year if INCOME>2 & L.credit_boom_3!=., re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/499))

scalar list 
scalar drop _all
drop hatx

*Column (4)
xtprobit SHOCK_3 L.info_cov $X i.year if INCOME>2 & L.credit_boom_3!=., re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_cov $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/499))
scalar list 
scalar drop _all
drop hatx


*Column (5)
xtprobit SHOCK_3 L.info_depth $X i.year if INCOME<3 & L.credit_boom_3!=., re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/478))
scalar list 
scalar drop _all
drop hatx

*Column (6)
xtprobit SHOCK_3 L.info_cov $X i.year if INCOME<3 & L.credit_boom_3!=., re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_cov $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/478))
scalar list 
scalar drop _all
drop hatx


	**************************
	*  SENSITIVITY ANALYSIS  *
	**************************

	***Table 4
*Panel A
global X L.gdppc L.pcgdp L.inflation L.growth L.capital L.Der L.HHI
forvalue i=1(1)5 {
gen shock_`i'=1 if D_NPL>=`i' & D_NPL!=.
replace shock_`i'=0 if D_NPL<`i'
table shock_`i'
xtprobit shock_`i' L.info_cov $X i.year if sample==1, re 
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit shock_`i' L.info_cov $X i.year if sample==1, re 
scalar lnlA=e(ll)
quietly xtprobit shock_`i' if sample==1, re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/977))
scalar list 
scalar drop _all
drop hatx
drop shock_`i'
}
xtreg D_NPL L.info_depth $X i.year if sample==1, re 
xtreg D_NPL L.info_cov $X i.year if sample==1, re 



*Panel B
preserve
keep if INCOME>2
global X L.gdppc L.pcgdp L.inflation L.growth L.capital L.Der L.HHI
forvalue i=1(1)5 {
gen shock_`i'=1 if D_NPL>=`i' & D_NPL!=.
replace shock_`i'=0 if D_NPL<`i'
table shock_`i'
xtprobit shock_`i' L.info_cov $X i.year if sample==1, re 
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit shock_`i' L.info_cov $X i.year if sample==1, re 
scalar lnlA=e(ll)
quietly xtprobit shock_`i' if sample==1, re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/977))
scalar list 
scalar drop _all
drop hatx
drop shock_`i'
}
xtreg D_NPL L.info_depth $X i.year if sample==1, re 
xtreg D_NPL L.info_cov $X i.year if sample==1, re 

restore


*Panel C
preserve
keep if INCOME<=2
global X L.gdppc L.pcgdp L.inflation L.growth L.capital L.Der L.HHI
forvalue i=1(1)5 {
gen shock_`i'=1 if D_NPL>=`i' & D_NPL!=.
replace shock_`i'=0 if D_NPL<`i'
table shock_`i'
xtprobit shock_`i' L.info_cov $X i.year if sample==1, re 
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit shock_`i' L.info_cov $X i.year if sample==1, re 
scalar lnlA=e(ll)
quietly xtprobit shock_`i' if sample==1, re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/977))
scalar list 
scalar drop _all
drop hatx
drop shock_`i'
}
xtreg D_NPL L.info_depth $X i.year if sample==1, re 
xtreg D_NPL L.info_cov $X i.year if sample==1, re 

restore



	***Table 5
			
xtset id year
global X L.gdppc L.pcgdp L.inflation L.growth L.capital L.Der L.HHI


*Column (1)
xtprobit SHOCK_3 L.credit_boom_5 L.info_depth $X i.year, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "credit_boom_5" "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/478))
scalar list 
scalar drop _all
drop hatx

*Column (2)
xtprobit SHOCK_3 L.credit_boom_5 L.info_cov $X i.year, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "credit_boom_5" "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/478))
scalar list 
scalar drop _all
drop hatx

*Column (3)
xtprobit SHOCK_3 L.credit_boom_5 L.info_depth $X i.year if INCOME>2, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "credit_boom_5" "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/478))
scalar list 
scalar drop _all
drop hatx

*Column (4)
xtprobit SHOCK_3 L.credit_boom_5 L.info_cov $X i.year if INCOME>2, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "credit_boom_5" "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/478))
scalar list 
scalar drop _all
drop hatx

*Column (5)
xtprobit SHOCK_3 L.credit_boom_5 L.info_depth $X i.year if INCOME<3, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "credit_boom_5" "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/478))
scalar list 
scalar drop _all
drop hatx

*Column (6)
xtprobit SHOCK_3 L.credit_boom_5 L.info_cov $X i.year if INCOME<3, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "credit_boom_5" "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit SHOCK_3 L.info_depth $X i.year if L.credit_boom_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit SHOCK_3 if L.credit_boom_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/478))
scalar list 
scalar drop _all
drop hatx


	***Table 6 
gen Inter1=L.credit_boom_5*L.info_depth
gen Inter2=L.credit_boom_5*L.info_cov
					

xtset id year
global X L.gdppc L.pcgdp L.inflation L.growth L.capital L.Der L.HHI
***All countries 
qui xtreg SHOCK_3 L.credit_boom_5 L.info_depth Inter1 $X i.year, re ro
eststo eq1
qui xtreg SHOCK_3 L.credit_boom_5 L.info_cov Inter2 $X i.year, re ro
eststo eq2
qui xtreg SHOCK_3 L.credit_boom_5 L.info_depth Inter1 $X i.year  if INCOME>2, re ro
eststo eq3
qui xtreg SHOCK_3 L.credit_boom_5 L.info_cov Inter2 $X i.year  if INCOME>2, re ro
eststo eq4
qui xtreg SHOCK_3 L.credit_boom_5 L.info_depth Inter1 $X i.year  if INCOME<3, re ro
eststo eq5
qui xtreg SHOCK_3 L.credit_boom_5 L.info_cov Inter2 $X i.year  if INCOME<3, re ro	
eststo eq6
esttab eq1 eq2 eq3 eq4 eq5 eq6, star (* 0.10 ** 0.05 *** 0.01)


	***Table 7

xtset id year
global X L.gdppc L.pcgdp L.inflation L.growth L.capital L.Der L.HHI

*Column (1)
xtprobit credit_boom_5 L.info_depth $X i.year if SHOCK_3!=., re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit credit_boom_5 L.info_depth $X i.year if SHOCK_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit credit_boom_5 if SHOCK_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/1083))

scalar list 
scalar drop _all
drop hatx

*Column (2)
xtprobit credit_boom_5 L.info_cov $X i.year if SHOCK_3!=., re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit credit_boom_5 L.info_cov $X i.year if SHOCK_3!=., re 
scalar lnlA=e(ll)
quietly xtprobit credit_boom_5 if SHOCK_3!=., re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/1083))

scalar list 
scalar drop _all
drop hatx

*Column (3)
xtprobit credit_boom_5 L.info_depth $X i.year if SHOCK_3!=. & INCOME>2, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit credit_boom_5 L.info_depth $X i.year if SHOCK_3!=. & INCOME>2, re 
scalar lnlA=e(ll)
quietly xtprobit credit_boom_5 if SHOCK_3!=. & INCOME>2, re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/555))

scalar list 
scalar drop _all
drop hatx

*Column (4)
xtprobit credit_boom_5 L.info_cov $X i.year if SHOCK_3!=. & INCOME>2, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit credit_boom_5 L.info_cov $X i.year if SHOCK_3!=. & INCOME>2, re 
scalar lnlA=e(ll)
quietly xtprobit credit_boom_5 if SHOCK_3!=. & INCOME>2, re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/555))

scalar list 
scalar drop _all
drop hatx

*Column (5)
xtprobit credit_boom_5 L.info_depth $X i.year if SHOCK_3!=. & INCOME<3, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_depth" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit credit_boom_5 L.info_depth $X i.year if SHOCK_3!=. & INCOME<3, re 
scalar lnlA=e(ll)
quietly xtprobit credit_boom_5 if SHOCK_3!=. & INCOME<3, re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/528))

scalar list 
scalar drop _all
drop hatx

*Column (6)
xtprobit credit_boom_5 L.info_cov $X i.year if SHOCK_3!=. & INCOME<3, re
predict hatx if e(sample)==1,xb
sum hatx
scalar XB=r(mean)
scalar DENS=normalden(XB)
foreach x in "info_cov" "gdppc" "pcgdp" "inflation" "growth" "capital" "Der" "HHI" {
scalar B_`x'=_b[L.`x']*DENS
}
quietly xtprobit credit_boom_5 L.info_cov $X i.year if SHOCK_3!=. & INCOME<3, re 
scalar lnlA=e(ll)
quietly xtprobit credit_boom_5 if SHOCK_3!=. & INCOME<3, re 
scalar lnl0=e(ll)
scalar pseudoR2=1-(1/(1+2*(lnlA-lnl0)/528))

scalar list 
scalar drop _all
drop hatx

